package com.docker.sys.dic;

import com.docker.core.constant.MainConstant;
import com.docker.core.mvc.dao.BaseDao;
import com.jfinal.kit.Okv;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;

public class DicDao extends BaseDao {

    @Override
    protected String getDbName() {
        return MainConstant.DB_DOCKER;
    }

    @Override
    protected String getSqlTplNameSpace() {
        return "sys.dic";
    }

    public List<Record> all(Okv cond) {
        return tplSPList("all", cond);
    }

    public List<Record> cacheList() {
        return tplList("cache.list");
    }

    public boolean codeExist(Okv cond) {
        Record code = tplSPInfo("code.exist", cond);
        if (StrKit.notNull(code)) {
            return code.getInt("count") > 0;
        }
        return false;
    }

    public Record nameExist(Okv cond) {
        return tplSPInfo("name.exist", cond);
    }

    public Record info(String dicId) {
        return info("sys_dic", "dic_id", dicId);
    }

    public boolean save(Record record) {
        return save("sys_dic", "dic_id", record);
    }

    public boolean update(Record record) {
        return update("sys_dic", "dic_id", record);
    }

    public boolean delete(String dicId) {
        return deleteById("sys_dic", "dic_id", dicId);
    }

    public void updateChild(String newCode, String dicPcode) {
        tplUpdate("update.child", newCode, dicPcode);
    }

}
